<?php

namespace App;
use Session;
use Illuminate\Database\Eloquent\Model;
use DB;
class Brand_Home extends Model{
   
    public function lists(){
      return DB::table('brand')->where('is_show',1)->orderBy('brand_sort','desc')->get(['brand_id','brand_name','brand_logo']);
    }


    //热销品牌
    public function hot_brand(){
        return DB::table('brand')->where('is_show',1)->orderBy('brand_sort','desc')->get(['brand_id','brand_name']);
    }
       //根据品牌id查商品
    public function goodsList($brand_id){
    	return DB::table('goods')->where('brand_id',$brand_id)->where('is_on_sale',1)->get(['goods_id','goods_name','goods_price','goods_img']);
    }

    //获取单条
    public function getOne($brand_id){
    	return DB::table('brand')->where('brand_id',$brand_id)->first();
    }

    //根据品牌id热销查商品
    public function hot($brand_id){
    	return DB::table('goods')->where('brand_id',$brand_id)->where('is_on_sale',1)->where('is_hot',1)->orderBy('sort','desc')->get(['goods_id','goods_name','goods_price','goods_img']);
    }

    ///根据品牌id查新品商品
    public function brand_new($brand_id){
    	return DB::table('goods')->where('brand_id',$brand_id)->where('is_on_sale',1)->where('is_new',1)->orderBy('sort','desc')->get(['goods_id','goods_name','goods_price','goods_img']);
    }

    //当前商品添加到收藏夹
    public function addgoods($goods_id,$user_id){
    	return DB::table('collect')->insert(['goods_id'=>$goods_id,'user_id'=>$user_id,'add_time'=>time(),'status'=>1]);
    }

    //判断当前用户有没有添加当前商品
    public function checkGoods($goods_id,$user_id){
    	return DB::table('collect')->where('goods_id',$goods_id)->where('user_id',$user_id)->get();
    }

}